<?php

namespace app\common\model\repair;

use app\common\model\BaseModel;
use app\common\model\room\RoomBasicModel;
use app\common\model\repair\RepairCateModel;
use app\common\model\repair\RepairPictureModel;
use app\common\model\property\basic\PropertyBasicModel;

class RepairOrderModel extends BaseModel
{
    protected $autoWriteTimestamp = true;
    protected $createTime = 'add_time';
    protected $updateTime = false;

    public static function tablePk(): string
    {
        return 'id';
    }

    public static function tableName(): string
    {
        return 'repair_order';
    }

    public function roomInfo()
    {
        return $this->hasOne(RoomBasicModel::class, 'id', 'room_id');
    }

    public function picture()
    {
        return $this->hasMany(RepairPictureModel::class, 'repair_id', 'id');
    }

    public function propertyInfo()
    {
        return $this->hasOne(PropertyBasicModel::class, 'id', 'property_id');
    }

    public function cateInfo()
    {
        return $this->hasOne(RepairCateModel::class, 'id', 'cate_id');
    }

    public function pictureInfo()
    {
        return $this->hasMany(RepairPictureModel::class, 'repair_id', 'id')->where('is_type', 1);
    }

    public function getPictureAttr()
    {
        return get_arr_column($this->pictureInfo()->field('show_src')->select()->toArray(), 'show_src');
    }

    public function acceptPictureInfo()
    {
        return $this->hasMany(RepairPictureModel::class, 'repair_id', 'id')->where('is_type', 2);
    }

    public function getAcceptPlictureAttr()
    {
        return get_arr_column($this->acceptPictureInfo()->field('show_src')->select()->toArray(), 'show_src');
    }
}
